import request from '@/utils/request'

/**
 * 获取商户订单分页列表
 * @param {Object} params 查询参数
 * @param {string} params.merchantId 商户ID
 * @param {number} params.status 订单状态(2:待处理,3:进行中,4:已完成)
 * @param {number} params.pageNo 页码
 * @param {number} params.pageSize 每页数量
 * @returns {Promise} 
 */
export function getMerchantOrderPage(params) {
  return request({
    url: '/order/page',
    method: 'get',
    params
  });
}

/**
 * 获取待处理订单数量
 * @param {string} merchantId 商户ID
 * @returns {Promise} 
 */
export function getPendingOrderCount(merchantId) {
  return request({
    url: '/order/pending/count',
    method: 'get',
    params: { merchantId }
  });
}

/**
 * 商户接单
 * @param {string} orderId 订单ID
 * @returns {Promise} 
 */
export function acceptOrder(orderId) {
  return request({
    url: '/order/accept/' + orderId,
    method: 'post'
  });
}

/**
 * 商户拒单
 * @param {string} orderId 订单ID
 * @param {string} cancelReason 取消原因
 * @returns {Promise} 
 */
export function rejectOrder(orderId, cancelReason) {
  return request({
    url: '/order/reject/' + orderId,
    method: 'post',
    params: { cancelReason }
  });
}

/**
 * 获取订单详情
 * @param {string} orderId 订单ID
 * @returns {Promise} 
 */
export function getOrderDetail(orderId) {
  return request({
    url: `/order/detail/${orderId}`,
    method: 'get'
  });
}

/**
 * 商户出餐
 * @param {string} orderId 订单ID
 * @returns {Promise} 
 */
export function finishMeal(orderId) {
  return request({
    url: '/order/finish-meal/' + orderId,
    method: 'post'
  });
}